//
//  SwitchPageViewCell.m
//  Rongcloud
//
//  Created by LiuLinhong on 2017/08/30.
//  Copyright © 2017年 Beijing Rongcloud Network Technology Co. , Ltd. All rights reserved.
//

#import "SwitchPageViewCell.h"

@implementation SwitchPageViewCell

- (instancetype)initWithFrame:(CGRect)frame withSwitchPage:(SwitchPageViewControl *)switchPage
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.switchPageViewControl = switchPage;
//        self.wantsLayer = YES;  //与视频GLView争抢主线程
//        self.layer.cornerRadius = 4.0;
    }
    
    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    
    [[NSColor blackColor] setFill];
    NSRectFill(dirtyRect);
}

- (void)mouseDown:(NSEvent *)event
{
    DLog(@"LLH...... mouseDown userID: %@", self.userID);
    [self.switchPageViewControl switchPageCellPressed:self.indexPath];
}

- (void)startLoadingAnimation
{
    /*
    self.loadingImageView = [[NSImageView alloc] initWithFrame:CGRectMake(40, 40, 80, 80)];
    //    logoImageView.layer.cornerRadius = 5.0;
    self.loadingImageView.image = [NSImage imageNamed:@"MeetingCloseCameraHeaderImage"];
    [self addSubview:self.loadingImageView];
    
    self.wantsLayer = YES;
    self.loadingImageView.wantsLayer = YES;
    
    self.loadingAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    self.loadingAnimation.duration = 1.0;
    self.loadingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    self.loadingAnimation.fromValue = @0.0f;
    self.loadingAnimation.toValue = [NSNumber numberWithFloat:-2 * M_PI];
    self.loadingAnimation.repeatCount = NSUIntegerMax;
    self.loadingAnimation.fillMode = kCAFillModeBackwards;
    
    self.loadingImageView.layer.anchorPoint = CGPointMake(0.5, 0.5);
    [self.loadingImageView.layer addAnimation:self.loadingAnimation forKey:@"rotation"];
    */
    
    self.indicator = [[NSProgressIndicator alloc] initWithFrame:self.bounds];
    [self.indicator setStyle:NSProgressIndicatorSpinningStyle];
    self.indicator.wantsLayer = YES;
    self.indicator.layer.backgroundColor = [NSColor clearColor].CGColor;
    self.indicator.controlSize = NSControlSizeRegular;
    self.indicator.controlTint = NSGraphiteControlTint;
    
    CIFilter *lighten = [CIFilter filterWithName:@"CIColorControls"];
    [lighten setDefaults];
    [lighten setValue:@1 forKey:@"inputBrightness"];
    [self.indicator setContentFilters:[NSArray arrayWithObjects:lighten, nil]];
    [self addSubview:self.indicator];
    [self.indicator startAnimation:nil];
}

- (void)stopLoadingAnimation
{
    /*
    self.wantsLayer = NO;
    self.loadingImageView.wantsLayer = NO;
    [self.loadingImageView.layer removeAnimationForKey:@"rotation"];
    [self.loadingImageView removeFromSuperview];
    self.loadingAnimation = nil;
     */
    [self.indicator removeFromSuperview];
    [self.indicator stopAnimation:nil];
}

@end
